#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    void count(int i, vector<int>& v)
    {
        int ans = 0;
        while (i)
        {
            i = i & (i - 1);
            ans++;
        }
        v.push_back(ans);
    }
    vector<int> countBits(int n) {
        vector<int> v;
        int i = 0;
        for (; i < n + 1; i++)
        {
            count(i, v);
        }
        return v;
    }
};
